home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / AppleEvents / Simple Descriptors / AESimpleDescriptor.h < prev   
Text File  |  2000-06-23  |  2KB  |  59 lines

  1. // AESimpleDescriptor.h
  2.  
  3. #ifndef AESimpleDescriptor_h
  4. #define AESimpleDescriptor_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9. #ifndef AEDescriptor_h
  10. #include "AEDescriptor.h"
  11. #endif
  12. #ifndef ConstData_h
  13. #include "ConstData.h"
  14. #endif
  15.  
  16. template < uint32 aeType, class ContainedType >
  17. class AESimpleDescriptor: public AEDescriptor
  18.   {
  19.     public:
  20.         AESimpleDescriptor()        {}
  21.         AESimpleDescriptor( const ContainedType& value )
  22.           : AEDescriptor( ConstData( &value, sizeof( ContainedType ) ), StaticType() )
  23.           {}
  24.         
  25.         static AEType StaticType()            { return AEType( aeType ); }
  26.         bool TypeIsCorrect() const            { return Type() == StaticType(); }
  27.         
  28.         bool SizeIsCorrect() const
  29.             { return  AEDescriptor::Value().Size() == sizeof( ContainedType ); }
  30.         
  31.         const ContainedType& Value() const
  32.           {
  33.             Assert( Allocated() );
  34.             Assert( TypeIsCorrect() );
  35.             Assert( !AEDescriptor::Value().IsEmpty() );
  36.             Assert( SizeIsCorrect() );
  37.             return *static_cast< ContainedType * >( AEDescriptor::Value().Pointer() );
  38.           }
  39.         
  40.         void Set( const ContainedType& value )
  41.           {
  42.             Assert( Allocated() );
  43.             Assert( TypeIsCorrect() );
  44.             Assert( !AEDescriptor::Value().IsEmpty() );
  45.             Assert( SizeIsCorrect() );
  46.             *static_cast< ContainedType * >( AEDescriptor::Value().Pointer() ) = value;
  47.           }
  48.         
  49.         void operator=( const ContainedType& newValue )
  50.           { Set( newValue ); }
  51.   };
  52.  
  53. typedef AESimpleDescriptor< typeShortInteger, int16 > AEInt16;
  54. typedef AESimpleDescriptor< typeLongInteger, int32 > AEInt32;
  55. typedef AESimpleDescriptor< typeMagnitude, uint32 > AEUInt32;
  56. typedef AESimpleDescriptor< typeFixed, Fixed > AEFixed;
  57.  
  58. #endif
  59.